package com.cjq.conf;


import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration()
@ConditionalOnClass(MinioClient.class) // 当类路径存在时生效
@EnableConfigurationProperties(MinioConfProperties.class) // 启用配置绑定
public class MinioConf {

    @Autowired
    private MinioConfProperties minioConfProperties;
    @Bean
    @ConditionalOnMissingBean // 用户未定义时生效
    /**
     * 关键配置:
     * minio.accessKey 用户名
     * minio.secretKey: 密码
     * minio.address: 客户端URL
     * minio.bucketName: 桶名称(可手动指定)
     */
    public MinioClient minioClient(){
        return MinioClient.builder()
                // MinIO服务地址
                .endpoint(minioConfProperties.getAddress())
                // 访问密钥和密码
                .credentials(minioConfProperties.getAccessKey(), minioConfProperties.getSecretKey())
                .build();
    }

}
